package com.bean;

import com.util.DateUtil;

import java.io.Serializable;
import java.util.Date;

public class User implements Serializable {
    private Integer id;
    private String userName;
    private String password;
    private String realName;
    private String phone;
    private String card;
    private Integer gender;
    private Integer age;
    private Integer role;
    private Integer spare;
    private Integer state;

    public User() {
    }

    public User(Integer id, String userName, String password) {
        this.id = id;
        this.userName = userName;
        this.password = password;
    }

    public User(String userName, String password, String realName, String phone, String card, Integer gender, Integer age, Integer role, Integer spare, Integer state) {
        this.userName = userName;
        this.password = password;
        this.realName = realName;
        this.phone = phone;
        this.card = card;
        this.gender = gender;
        this.age = age;
        this.role = role;
        this.spare = spare;
        this.state = state;
    }

    public User(Integer id, String userName, String password, String realName, String phone, String card, Integer gender, Integer age, Integer role, Integer spare, Integer state) {
        this.id = id;
        this.userName = userName;
        this.password = password;
        this.realName = realName;
        this.phone = phone;
        this.card = card;
        this.gender = gender;
        this.age = age;
        this.role = role;
        this.spare = spare;
        this.state = state;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                ", realName='" + realName + '\'' +
                ", phone='" + phone + '\'' +
                ", card='" + card + '\'' +
                ", gender=" + gender +
                ", age=" + age +
                ", role=" + role +
                ", spare=" + spare +
                ", state=" + state +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getCard() {
        return card;
    }

    public void setCard(String card) {
        this.card = card;
    }

    public Integer getGender() {
        return gender;
    }

    public void setGender(Integer gender) {
        this.gender = gender;
    }

    public Integer age() {
        String year = this.card.substring(6, 10);
        String month = this.card.substring(10,12);
        String day = this.card.substring(12,14);
        String birthday = year+"-"+month+"-"+day;
        int age=0;
        try {
            long time = DateUtil.parse(birthday, "yyyy-MM-dd").getTime();
            age = (int) ((System.currentTimeMillis() - time) / 1000 / 60 / 60 / 24 / 365);
        } catch (Exception e) {

        }
        return age;
    }

    public String gender(){
        String gender = this.card.substring(16,17);
        String xinbie = (Integer.valueOf(gender))%2 == 0 ? "女":"男";
        return xinbie;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Integer getRole() {
        return role;
    }

    public void setRole(Integer role) {
        this.role = role;
    }

    public Integer getSpare() {
        return spare;
    }

    public void setSpare(Integer spare) {
        this.spare = spare;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }
}
